package busuanzi.util;

import java.util.HashMap;
import java.util.HashSet;

/**
 * Auth: bruce-sha
 * Date: 2015/4/20
 * jdk collections, guava collections2, apache collection util, me collections3
 */
public abstract class Containers {

    public static <K, V> HashMap<K, V> newHashMap(Object... args) {
        final HashMap map = new HashMap(args.length / 2 + 1);
        for (int i = 0; i < args.length - 1; i = i + 2) map.put(args[i], args[i + 1]);
        return map;
    }

    public static <E> HashSet<E> newHashSet(Object... args) {
        final HashSet set = new HashSet(args.length);
        for (Object o : args) set.add(o);
        return set;
    }

    public static void main(String[] args) {
        System.out.println(newHashMap("a", 1, "b"));
        System.out.println(newHashMap("a", 1, "b", 2));
        System.out.println(newHashMap("a", 1, "b", 2, "v", 3));
    }

}
